{{Extend "layout"}}
{{Block "title"}}{{if HasSuffix $.URL.Path "_add"}}{{"添加用户"|$.T}}{{else}}{{"修改用户"|$.T}}{{end}}{{/Block}}
{{Block "breadcrumb"}}
{{Super}}
<li><a href="{{BackendURL}}/manager/user">{{"用户列表"|$.T}}</a></li>
<li class="active">{{if HasSuffix $.URL.Path "_add"}}{{"添加"|$.T}}{{else}}{{"修改"|$.T}}{{end}}</li>
{{/Block}}
{{Block "head"}}
<link rel="stylesheet" type="text/css" href="{{AssetsURL}}/js/jquery.select2/select2.css" />
{{/Block}}
{{Block "main"}}
<div class="row">
    <div class="col-md-12">
        <div class="block-flat no-padding">
          <div class="header">							
            <h3>{{if HasSuffix $.URL.Path "_add"}}{{"添加用户"|$.T}}{{else}}{{"修改用户"|$.T}}{{end}}</h3>
          </div>
          <div class="content">
              <form class="form-horizontal group-border-dashed" data-parsley-validate method="POST" id="profile-form" data-secret="{{SM2PublicKey}}:{{call $.Func.EnvKey}}" action="">
              <div class="form-group">
                  <label class="col-sm-2 control-label">{{"头像"|$.T}}</label>
                  <div class="col-sm-8">
                    <div class="avatar-upload">
                      {{$avatar := $.Form "avatar"}}
                      <img src="{{if $avatar}}{{AddSuffix $avatar "_200_200"}}{{else}}{{AssetsURL}}/images/user_128.png{{end}}" class="profile-avatar img-thumbnail" onerror="this.onerror=null;this.src='{{AssetsURL}}/images/user_128.png';" />
                      <input id="fileupload" type="file" name="files[]">
                      <input type="hidden" id="avatar-image" name="avatar-small" value="{{if $avatar}}{{AddSuffix $avatar "_200_200"}}{{end}}" />
                      <input type="hidden" id="avatar-image-original" name="avatar" value="{{$avatar}}" />
                      <div id="progress" class="overlay"></div>
                    </div>
                  </div>
                </div>
              <div class="form-group">
                <label class="col-sm-2 control-label">{{"用户名"|$.T}}</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" data-parsley-trigger="change" required name="username" value="{{$.Form "username"}}">
                </div>
              </div>
              {{if HasSuffix $.URL.Path "_edit"}}
              <div class="form-group">
                <label class="col-sm-2 control-label"></label>
                <div class="col-sm-8">
                    <label>
                    <input type="checkbox" data-parsley-trigger="change" name="modifyPwd" value="1"{{if $.Form "modifyPwd"}} checked{{end}}>
                    {{"修改密码"|$.T}}</label>
                </div>
              </div>
              <div class="form-group new-password">
                <label class="col-sm-2 control-label">{{"新密码"|$.T}}</label>
                <div class="col-sm-8">
                  <input type="password" class="form-control" data-parsley-trigger="change" name="password" value="{{$.Form "password"}}">
                </div>
              </div>
              <div class="form-group new-password">
                <label class="col-sm-2 control-label">{{"确认新密码"|$.T}}</label>
                <div class="col-sm-8">
                  <input type="password" class="form-control" data-parsley-trigger="change" name="confirmPwd" value="{{$.Form "confirmPwd"}}">
                </div>
              </div>
              {{else}}
              <div class="form-group">
                <label class="col-sm-2 control-label">{{"密码"|$.T}}</label>
                <div class="col-sm-8">
                  <input type="password" class="form-control" data-parsley-trigger="change" required name="password" value="{{$.Form "password"}}">
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-2 control-label">{{"确认密码"|$.T}}</label>
                <div class="col-sm-8">
                  <input type="password" class="form-control" data-parsley-trigger="change" required name="confirmPwd" value="{{$.Form "confirmPwd"}}">
                </div>
              </div>
              {{end}}
              <div class="form-group">
                <label class="col-sm-2 control-label">{{"E-mail"|$.T}}</label>
                <div class="col-sm-8">
                  <input type="email" class="form-control" data-parsley-trigger="change" required name="email" value="{{$.Form "email"}}">
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-2 control-label">{{"手机号码"|$.T}}</label>
                <div class="col-sm-8">
                  <input type="text" class="form-control" data-parsley-trigger="change" required name="mobile" value="{{$.Form "mobile"}}">
                </div>
              </div>
              <div class="form-group">
                  <label class="col-sm-2 control-label">{{"性别"|$.T}}</label>
                  <div class="col-sm-8">
                    {{$v := $.Form "gendar"}}
                    <div class="radio radio-primary radio-inline">
                      <input type="radio" value="secret" name="gendar" id="gendar-secret"{{if or (eq $v "secret") (eq $v "")}} checked{{end}}> <label for="gendar-secret">{{"保密"|$.T}}</label>
                    </div>
                    <div class="radio radio-primary radio-inline">
                      <input type="radio" value="female" name="gendar" id="gendar-female"{{if eq $v "female"}} checked{{end}}> <label for="gendar-female">{{"女"|$.T}}</label>
                    </div>
                    <div class="radio radio-primary radio-inline">
                      <input type="radio" value="male" name="gendar" id="gendar-male"{{if eq $v "male"}} checked{{end}}> <label for="gendar-male">{{"男"|$.T}}</label>
                    </div>
                  </div>
              </div>
              <div class="form-group">
                <label class="col-sm-2 control-label">{{"状态"|$.T}}</label>
                <div class="col-sm-8">
                  {{$v := $.Form "disabled"}}
                  <div class="radio radio-primary radio-inline"> 
                    <input type="radio" value="N" id="disabled-N" name="disabled"{{if or (eq $v "N") (eq $v "")}} checked{{end}}><label for="disabled-N">{{"启用"|$.T}}</label> 
                  </div>
                  <div class="radio radio-danger radio-inline"> 
                    <input type="radio" value="Y" id="disabled-Y" name="disabled"{{if eq $v "Y"}} checked{{end}}><label for="disabled-Y">{{"禁用"|$.T}}</label> 
                  </div>
                </div>
              </div>
              <div class="form-group">
                <label class="col-sm-2 control-label">{{"角色"|$.T}}</label>
                <div class="col-sm-8">
                  <select id="select2roles" data-parsley-trigger="change" required name="roleIds" multiple="multiple">
                    {{range $k, $v := $.Stored.roleList}}
                    <option value="{{$v.Id}}"{{if call $.Func.isChecked $v.Id}} selected="selected"{{end}}>{{$v.Name}}</option>
                    {{end}}
                  </select>
                </div>
              </div>
              <div class="form-group form-submit-group">
									<div class="col-sm-9 col-sm-offset-2">
									  <button type="submit" class="btn btn-primary btn-lg"><i class="fa fa-save"></i> {{"保存"|$.T}}</button>
									  <button type="reset" class="btn btn-default btn-lg"><i class="fa fa-refresh"></i> {{"重置"|$.T}}</button>
									</div>
							</div>
            </form>
          {{Include "modal_crop_image"}}
          </div><!-- /.content -->
        </div><!-- /.block-flat -->
    </div>
</div>
{{/Block}}
{{Block "footer"}}
<script src="{{AssetsURL}}/js/jquery.select2/select2.min.js" type="text/javascript"></script>
<script src="{{AssetsURL}}/js/loader/loader.min.js?t={{BuildTime}}"></script>
<script src="{{AssetsURL}}/js/editor/editor.min.js?t={{BuildTime}}"></script>
<script type="text/javascript" src="{{AssetsURL}}/js/crypto/crypto-js.min.js?t={{BuildTime}}"></script>
<script type="text/javascript" src="{{AssetsURL}}/js/crypto/sm2.min.js?t={{BuildTime}}"></script>
<script type="text/javascript" src="{{AssetsURL}}/js/crypto/helper.min.js?t={{BuildTime}}"></script>
<script type="text/javascript">
$(function(){
//{{if HasSuffix $.URL.Path "_edit"}}
  $('input[name="modifyPwd"]').on('click',function(){
    if($(this).prop('checked')){
      $('.new-password').show();
    }else{
      $('.new-password').hide();
    }
  });
  if($('input[name="modifyPwd"]').prop('checked')){
    $('.new-password').show();
  }else{
    $('.new-password').hide();
  }
//{{end}}
  $('#select2roles').select2({width:'100%'});
  App.editor.cropImage('{{BackendUploadURL "avatar"}}',"#avatar-image",'#avatar-image-original');
  submitEncryptedData('#profile-form');
});
</script>
{{/Block}}